<?php

namespace app\admin\controller;

use app\model\Config as configModel;
use app\model\ConfigUpload as uploadModel;

class Set extends Base
{
    protected function _infoModule()
    {
        return array(
            'info' => array(
                'name' => '系统设置',
                'description' => '管理网站后台管理员',
            ),
            'menu' => array(
                array(
                    'name' => '站点信息',
                    'url' => url('set/site'),
                    'icon' => 'list',
                ),
                array(
                    'name' => '模板设置',
                    'url' => url('set/tpl'),
                    'icon' => 'eye',
                ),
                array(
                    'name' => '手机设置',
                    'url' => url('set/mobile'),
                    'icon' => 'mobile',
                ),
                array(
                    'name' => '上传设置',
                    'url' => url('set/upload'),
                    'icon' => 'upload',
                ),
                array(
                    'name' => '短信配置',
                    'url' => url('set/sms'),
                    'icon' => 'sms',
                ),
            ),
            '_info' => array(),
        );
    }

    /**
     * 站点设置
     */
    public function site()
    {
        $request = $this->request;
        $method = $request->method();
        $configModel = new configModel;
        if ($method == 'POST') {
            if ($configModel->editAll($request)) {
                jsonApi(1, '配置成功！', ['url'=>url('site')]);
            } else {
                jsonApi(0, '配置失败！');
            }
        } else {
            $info = $configModel->getInfo();
            $this->assign('info', $info);

            $this->fetch('site');
        }
    }

    /**
     * 模板设置
     */
    public function tpl()
    {
        $request = $this->request;
        $method = $request->method();
        $configModel = new configModel;
        if ($method == 'POST') {
            if ($configModel->editAll($request)) {
                jsonApi(1, '配置成功！', ['url'=>url('tpl')]);
            } else {
                jsonApi(0, '配置失败！');
            }
        } else {
            $info = $configModel->getInfo();
            $this->assign('info', $info);

            $this->fetch('tpl');
        }
    }

    /**
     * 手机设置
     */
    public function mobile()
    {
        $request = $this->request;
        $method = $request->method();
        $configModel = new configModel;
        if ($method == 'POST') {
            if ($configModel->editAll($request)) {
                jsonApi(1, '配置成功！', ['url'=>url('mobile')]);
            } else {
                jsonApi(0, '配置失败！');
            }
        } else {
            $info = $configModel->getInfo();
            $this->assign('info', $info);

            $this->fetch('mobile');
        }
    }

    /**
     * 上传设置
     */
    public function upload()
    {
        $request = $this->request;
        $method = $request->method();
        $uploadModel = new uploadModel;
        if ($method == 'POST') {
            if ($uploadModel->editAll($request)) {
                jsonApi(1, '上传设置成功！', ['url'=>url('upload')]);
            } else {
                jsonApi(0, '上传设置失败！');
            }
        } else {
            $info = $uploadModel->getInfo(['id'=>1]);
            $this->assign('info', $info);

            $this->fetch('upload');
        }
    }

    /**
     * 短信配置
     */
    public function sms()
    {
        $request = $this->request;
        $method = $request->method();
        $configModel = new configModel;
        if ($method == 'POST') {
            if ($configModel->editAll($request)) {
                jsonApi(1, '配置成功！', ['url'=>url('sms')]);
            } else {
                jsonApi(0, '配置失败！');
            }
        } else {
            $info = $configModel->getInfo();
            $this->assign('info', $info);

            $this->fetch('sms');
        }
    }

}
